home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoSetRootEntry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.0 KB  |  211 lines

  1. /*
  2.  *   $RCSfile: undoSetRootEntry.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "pool.h"
  46. #include "tid.h"
  47. #include "io.h"
  48. #include "lock.h"
  49. #include "object.h"
  50. #include "msgdefs.h"
  51. #include "thread.h"
  52. #include "latch.h"
  53. #include "semaphore.h"
  54. #include "link.h"
  55. #include "lsn.h"
  56. #include "bf.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "logrecs.h"
  60. #include "undo.h"
  61. #include "io_logfuncs.h"
  62. #include "io_extfuncs.h"
  63. #include "undo_extfuncs.h"
  64. #include "bf_extfuncs.h"
  65. #include "util_funcs.h"
  66. #include "thread_globals.h"
  67.  
  68.  
  69.  void
  70. undoSetRootEntry (
  71.  
  72.     LOGRECORDHDR        *recordHeader 
  73. )
  74. {
  75.  
  76.     register ROOTENTRY    *current;
  77.     register ROOTENTRY    *end;
  78.     register VOLREC        *volRec;
  79.     register GROUPLINK    *rootLink;
  80.     ROOTPAGE            *rootPage;
  81.     char                *oldData;
  82.     int                    oldDataSize;
  83.     PID                    pid;
  84.     VOLID                volid;
  85.     ROOTENTRYLOGINFO    *entryInfo;
  86.  
  87.  
  88.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
  89.  
  90.     /*
  91.      *    get a pointer to the volume id in the record
  92.      */
  93.     volid = recordHeader->actionPid.volid;
  94.     TRPRINT(TR_IO, TR_LEVEL_2, ("volid:%d", volid));
  95.  
  96.     /* get a pointer to information about the entry */
  97.     entryInfo = (ROOTENTRYLOGINFO*) GET_LOG_IMAGE(recordHeader, 0);
  98.     TRPRINT(TR_IO, TR_LEVEL_2, ("name:%s", entryInfo->name));
  99.     TRPRINT(TR_IO, TR_LEVEL_2, ("oldFlags:%d", entryInfo->oldFlags));
  100.  
  101.     /*
  102.      *    get a pointer to the old data and its size in the record
  103.      */
  104.     oldData = GET_LOG_IMAGE(recordHeader, 1);
  105.     oldDataSize = GET_LOG_IMAGE_SIZE(recordHeader, 1);
  106.     TRPRINT(TR_IO, TR_LEVEL_2, ("oldData:%s", oldData));
  107.  
  108.     if ((volRec = io_FindVolRec(volid)) == NULL)    {
  109.         SM_ERROR(TYPE_FATAL, Active->errno);
  110.     }
  111.  
  112.     /*
  113.      *    construct the pid of the header page
  114.      */
  115.     pid.volid = volid;
  116.     pid.page  = ROOTPAGEADDR;
  117.     SM_ASSERT(LEVEL_3, ROOTPAGEADDR == recordHeader->actionPid.page);
  118.  
  119.     /*
  120.      *    read in the root page
  121.      */
  122.     if ((rootLink = bf_ReadPage(volRec->bufGroup, &pid, MIN_PAGE2SIZE, BF_SEM)) == NULL) {
  123.  
  124.         SM_ERROR(TYPE_FATAL, Active->errno);
  125.     }
  126.  
  127.     /*
  128.      *    get a pointer to the root page
  129.      */
  130.     rootPage = (ROOTPAGE *) rootLink->bufFrame;
  131.  
  132.     /*
  133.      *    Initialize the search variables
  134.      */
  135.     current = &(rootPage->entry[0]);
  136.     end = &(rootPage->entry[MAX_ROOT_ENTRIES]);
  137.     
  138.     /*
  139.      *    look for a free spot
  140.      */
  141.     while (current < end)    {
  142.  
  143.         /*
  144.          *    check to see if the slot is free
  145.          */
  146.         if (current->flags != ROOT_FREE)    {
  147.  
  148.             /*
  149.              *    check to see if the name matches
  150.              */
  151.             if (!strcmp(current->name, (char *)entryInfo->name))    {
  152.  
  153.                 TRPRINT(TR_IO, TR_LEVEL_2, ("found name at slot:%d", current->index));
  154.  
  155.                 /*
  156.                  *    log the changes
  157.                  */
  158.                 if (io_LogUndoSetRootEntry(current->name, oldData,
  159.                     oldDataSize, entryInfo->oldFlags, 
  160.                     recordHeader->previousLSN, rootLink->pageHash))    {
  161.  
  162.                     bf_UnfixPage(rootLink, BF_DEFAULT, FALSE);
  163.                     SM_ERROR(TYPE_FATAL, Active->errno);
  164.                 }
  165.             
  166.  
  167.                 /*
  168.                  *    See if the entry was originally free
  169.                  */
  170.                 if (entryInfo->oldFlags == ROOT_FREE) {
  171.  
  172.                     /*
  173.                      *    free the entry
  174.                      */
  175.                     current->flags = ROOT_FREE;
  176.                 } else {
  177.  
  178.                     /*
  179.                      *    Restore the old data
  180.                      */
  181.                     bcopy(oldData, current->data, oldDataSize);
  182.                     current->dataSize = oldDataSize;
  183.                     current->flags = ROOT_USED;
  184.                 }
  185.  
  186.                 /*
  187.                  *    signal the semaphore and unfix the page
  188.                  */
  189.                 signalSemaphore( &(rootLink->pageHash->semaphore) );
  190.                 bf_UnfixPage(rootLink, BF_DEFAULT, TRUE);
  191.         
  192.                 /*
  193.                  *    return success
  194.                  */
  195.                 return;
  196.             }
  197.         }
  198.  
  199.         /*
  200.          *    look at the next entry
  201.          */
  202.         current++;
  203.     }
  204.  
  205.     /*
  206.      *    return an error
  207.      */
  208.     TRPRINT(TR_IO, TR_LEVEL_2, ("name not found"));
  209.     SM_ERROR(TYPE_FATAL, esmBADROOTNAME);
  210. }
  211.